<template>
  <div>
    <el-card :bordered="false" dis-hover class="ivu-mt">
      <el-form
        ref="artFrom"
        :model="questionFrom"
        label-width="50px"
        label-position="left"
        @submit.native.prevent
        inline
      >
        <el-form-item label="搜索：" label-for="nickname">
          <el-input
            v-model="questionFrom.keywords"
            placeholder="请输入搜索关键字"
            element-id="nickname"
            clearable
          >
            <el-select v-model="questionFrom.fieldKey" slot="prepend" style="width: 100px">
              <el-option value="id" label="id"></el-option>
              <el-option value="title" label="称呼"></el-option>
              <el-option value="login_name" label="账号"></el-option>
              <el-option value="name" label="姓名"></el-option>
              <el-option value="phone" label="联系电话"></el-option>
            </el-select>
          </el-input>
        </el-form-item>

        <el-form-item label="城市:" label-for="city_id">
          <el-select v-model="questionFrom.cityId" @change="CitySelect">
            <el-option value="all" label="全部"></el-option>
            <el-option
              :value="item.id"
              v-for="item in city_list"
              :key="item.id"
              :label="item.cityName"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button
            type="primary"
            icon="ios-search"
            label="default"
            class="mr15"
            @click="orderSearchs"
          >搜索</el-button>
          <el-button class="ResetSearch" @click="reset('questionFrom')">重置</el-button>
        </el-form-item>

        <el-row type="flex">
          <el-col v-bind="grid">
            <el-button
              type="primary"
              class="mr20"
              @click="edit(0)"
              v-hasPermi="['staff-add']"
            >添加服务人员</el-button>
          </el-col>
        </el-row>
        <el-table
          :data="staffList"
          ref="table"
          class="mt25"
          :loading="loading"
          highlight-row
          no-userFrom-text="暂无数据"
          no-filtered-userFrom-text="暂无筛选结果"
        >
          <el-table-column label="ID" min-width="100" fixed="left">
            <template slot-scope="scope">{{scope.row.id}}</template>
          </el-table-column>
          <el-table-column label="姓名" min-width="150">
            <template slot-scope="{ row, index }">
              <div>姓名：{{row.name}}</div>
              <div>称呼：{{row.title}}</div>
              <div v-if="row.compang_id > 0">门店：{{row.companyName}}</div>
            </template>
          </el-table-column>
          <el-table-column label="登录账号" min-width="150">
            <template slot-scope="scope">{{scope.row.loginName}}</template>
          </el-table-column>
          <el-table-column label="联系电话" min-width="150">
            <template slot-scope="scope">{{scope.row.phone}}</template>
          </el-table-column>
          <el-table-column label="评分" min-width="80">
            <template slot-scope="scope">{{scope.row.serviceScoreStar}}</template>
          </el-table-column>
          <el-table-column label="是否禁用" min-width="150">
            <template slot-scope="{row ,index}">
              <el-switch
                v-model="row.isDisable"
                :value="row.isDisable"
                :active-value="1"
                :inactive-value="0"
                @change="setDisable(row)"
                size="large"
                active-text="是"
                inactive-text="否"
              ></el-switch>
            </template>
          </el-table-column>
          <el-table-column label="添加时间" min-width="150">
            <template slot-scope="scope">{{ scope.row.addTimeStr}}</template>
          </el-table-column>
          <el-table-column label="操作" min-width="200" fixed="right">
            <template slot-scope="{ row, index }">
              <a @click="getStaffRelate(row)">服务项目</a>
              <el-divider direction="vertical" />
              <a @click="edit(row.id)">详情</a>
              <!-- <el-divider type="vertical" />
              <a @click="quality (row)">资质</a>-->
              <el-divider direction="vertical" />
              <a @click="del(row, '删除人员')">删除</a>
            </template>
          </el-table-column>
        </el-table>
        <div class="acea-row row-right page">
          <el-pagination
            :total="total"
            :current-page="questionFrom.page"
            show-elevator
            show-total
            @current-change="pageChange"
            :page-size="questionFrom.limit"
          />
        </div>
      </el-form>
    </el-card>
    <el-dialog :visible.sync="modals" title="人员详情" width="75%" >
    <staffEdit
      ref="staffEdit"
      v-if="modals"
      :modals="modals"
      :id="staff_id"
      @submitSuccess="submitSuccess"
    ></staffEdit>
    </el-dialog>

    <el-dialog :visible.sync="staffRelateModals" title="关联项目" class="order_box" width="800">
      <staffRelate ref="staffRelate" v-if="staffRelateModals" :staff_id="staff_id"></staffRelate>
      <div slot="footer">
        <el-button @click="staffRelateModals = false">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// import { formatDate } from '@/utils/validate';
import staffEdit from './handle/staffEdit.vue';
import staffRelate from './handle/staffRelate.vue';
import { cityList, getStaffListApi, setStaffDisableApi, staffDelApi } from '@/api/base';

export default {
  name: 'staff_list',
  components: {
    staffEdit,
    staffRelate,
  },
  data() {
    return {
      grid: {
        xl: 7,
        lg: 7,
        md: 12,
        sm: 24,
        xs: 24,
      },
      modals: false,
      staffRelateModals: false,
      questionFrom: {
        keywords: '',
        fieldKey: 'title',
        isRecommend: 'all',
        page: 1,
        limit: 10,
        cityId: 'all',
      },
      city_list: [], //城市列表
      cityId: 'all',
      staffList: [],

      loading: false,
      total: 0,
      staff_id: 0,
    };
  },

  created() {
    // this.questionFrom.cate_id = this.$route.query.id ? this.$route.query.id : 0;
    // this.getCategory();
    this.getList();
    this.getCitys();
  },
  activated() {
    // this.questionFrom.cate_id = this.$route.query.id ? this.$route.query.id : 0;
    // this.getCategory();
    this.getList();
  },
  mounted() {},
  methods: {
    getList() {
      this.loading = true;
      getStaffListApi(this.questionFrom)
        .then(async (res) => {
          let data = res;
          let list = res.list;
          let count = res.total;
          this.total = count;
          this.staffList = list;
          this.loading = false;
        })
        .catch((res) => {
          this.loading = false;
          this.$Message.error(res.msg);
        });
    },
    pageChange(index) {
      this.questionFrom.page = index;
      this.getList();
    },
    selectCategory() {
      this.questionFrom.page = 1;
      this.getList();
    },
    selectType(e) {
      this.questionFrom.page = 1;
      this.getList();
    },
    examSearchs(e) {
      this.questionFrom.page = 1;
      this.getList();
    },
    // 服务项目
    service_staff(row) {
      // this.getStaffFrom(row.id);
      // this.$modalForm(getStaffExamineApi({id:row.id})).then(() => this.getList());
    },
    setDisable(row) {
      let form = {
        id: row.id,
        isDisable: row.isDisable,
      };

      setStaffDisableApi(form)
        .then((row) => {
          this.$message.success('操作成功');
          this.getList();
        })
        .catch((err) => {
          this.$Message.error('操作失败');
        });
    },
    // 编辑
    edit(id) {
      if (id ) {
        this.staff_id = id;
      }
      this.modals = true;

    },
    //资质编辑
    quality(row) {
      this.getStaffAuthForm(row.id);
    },
    // 人员数据提交
    setStaff() {
      this.$refs.staffEdit.submit();
    },
    submitSuccess() {
      this.getList();
      this.staff_id = 0;
      this.modals = false;
    },
    // 人员服务项目
    getStaffRelate(date) {
      this.staffRelateModals = true;
      this.staff_id = date.id;
      // this.$modalForm(getStaffRelateApi({id:date.id})).then(() => this.getList());
    },
    // 表格搜索
    orderSearchs() {
      this.questionFrom.page = 1;
      this.getList();
    },
    // 重置
    reset() {
      (this.questionFrom = {
        keywords: '',
        fieldKey: 'title',
        page: 1,
        limit: 10,
        cityId: 'all',
      }),
        (this.cityId = 'all');
      this.getList();
    },
    // 删除
    del(row, tit) {
      this.$modalSure(`删除【${row.name}】`).then(() => {
        staffDelApi(row.id)
          .then((res) => {
            this.$message.success('删除成功');
            this.getList();
          })
          .catch((err) => {
            this.$message.error('删除失败');
          });
      });
    },
    //获取城市列表
    getCitys() {
      cityList({page:1,limit: 999}).then((res) => {
        let data = res;
        this.city_list = data.list;
      });
    },
    //选择城市
    CitySelect(e) {
      this.getList();
    },
  },
};
</script>

<style scoped lang="stylus">
.search-box {
  display: flex;
  align-items: center;
  column-gap: 10px;
}

.search-box>div {
  flex-shrink: 0;
}

.treeSel >>>.ivu-select-dropdown-list {
  padding: 0 10px !important;
  box-sizing: border-box;
}

.tabBox_img {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  cursor: pointer;

  img {
    width: 100%;
    height: 100%;
  }
}
</style>
